<template>
  <div id="app">
    <nav class="navbar">
      <div class="nav-container">
        <div class="nav-logo">
          <h2>在线商城</h2>
        </div>
        <ul class="nav-menu">
          <li class="nav-item">
            <router-link to="/" class="nav-link">首页</router-link>
          </li>
          <li class="nav-item">
            <router-link to="/products" class="nav-link">商品</router-link>
          </li>
          <li class="nav-item">
            <router-link to="/cart" class="nav-link">购物车</router-link>
          </li>
          <li class="nav-item">
            <router-link to="/orders" class="nav-link">订单</router-link>
          </li>
          <li class="nav-item">
            <router-link to="/profile" class="nav-link">个人中心</router-link>
          </li>
        </ul>
        <div class="nav-cart" @click="goToCart">
          <CartIcon :item-count="cartItemCount" />
        </div>
      </div>
    </nav>
    <main class="main-content">
      <router-view />
    </main>
    <footer class="footer">
      <p>&copy; 2025 在线商城. 保留所有权利.</p>
    </footer>
  </div>
</template>

<script>
import CartIcon from './components/CartIcon.vue'

export default {
  name: 'App',
  components: {
    CartIcon
  },
  data() {
    return {
      cartItemCount: 3 // 模拟购物车商品数量
    }
  },
  methods: {
    goToCart() {
      this.$router.push('/cart')
    }
  }
}
</script>

<style>
@import './styles/global.css';

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.1);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
}

.nav-logo h2 {
  color: #42b983;
}

.nav-menu {
  display: flex;
  list-style: none;
}

.nav-item {
  margin-left: 1.5rem;
}

.nav-link {
  text-decoration: none;
  color: #333;
  font-weight: 500;
  transition: color 0.3s;
}

.nav-link:hover {
  color: #42b983;
}

.router-link-active {
  color: #42b983;
  font-weight: bold;
}

.nav-cart {
  cursor: pointer;
}

.main-content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
}

.footer {
  background-color: #333;
  color: white;
  text-align: center;
  padding: 1rem 0;
  margin-top: auto;
}

@media (max-width: 768px) {
  .nav-container {
    flex-direction: column;
  }
  
  .nav-menu {
    margin-top: 1rem;
  }
  
  .nav-item {
    margin: 0 0.5rem;
  }
}
</style>